import actions from '../action/group';
import CONSTANT from '../constant/group';

const groupCollectionList = [];
const groupCollectionPage = {
  page: 1,
  size: 10,
  isActive: true,
  keyword: '',
};

const groupList = [];
const groupCollectionAppIdList = [];
const groupPage = {
  page: 1,
  size: 10,
  total: 0,
  isActive: true,
  keyword: '',
};

export default {
  actions,
  state: {
    groupCollectionList,
    groupCollectionPage,
    groupList,
    groupPage,
    groupCollectionAppIdList,
  },
  mutations: {
    [CONSTANT.GROUP_UPLOAD_IMG_SUCCESS](state) {
      return state;
    },
    [CONSTANT.GROUP_GET_SUCCESS](state, { page, groups }) {
      state.groupList = groups;
      state.groupPage = {
        ...state.groupPage,
        page: page.currentPage,
        size: page.pageSize,
        total: page.totalElement,
      };
    },
    [CONSTANT.GROUP_COLLECTION_GET_SUCCESS](state, { groupCollectionResponses, page }) {
      state.groupCollectionList = groupCollectionResponses;
      state.groupCollectionPage = {
        ...state.groupCollectionPage,
        page: page.currentPage,
        size: page.pageSize,
        total: page.totalElement,
      };
    },
    [CONSTANT.PUBLICACCOUNT_GET_SUCCESS](state) {
      return state;
    },
    [CONSTANT.GROUP_DETAIL_GET_SUCCESS](state) {
      return state;
    },
    [CONSTANT.GROUP_GET_IMG_SUCCESS](state) {
      return state;
    },
    [CONSTANT.GROUP_COLLECTION_DETAIL_GET_SUCCESS](state) {
      return state;
    },
    [CONSTANT.GROUP_GET_COLLECTION_BY_APPID_SUCCESS](state, list) {
      state.groupCollectionAppIdList = list;
    },
    [CONSTANT.GROUP_GET_COLLECTION_BY_APPID_ERROR](state) {
      state.groupCollectionAppIdList = [];
    },
  },
  getters: {
    [CONSTANT.GROUP_UPLOAD_IMG_SUCCESS](state) {
      return state;
    },
    [CONSTANT.GROUP_COLLECTION_ADD_SUCCESS](state) {
      return state;
    },
  },
};
